package com.example.sqlite;

import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.view.Menu;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.SimpleCursorAdapter;

public class MainActivity extends Activity {

	private DBAdapter mDB;
	private Cursor mCursor;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		mDB = new DBAdapter(this);
		mDB.open();
		mDB.createUser("Nguyen Thai Nhan");
		getData();
	}

	private void getData(){
		mCursor = mDB.getAllUsers();
    	startManagingCursor(mCursor);
    	String[] from = new String[]{DBAdapter.KEY_NAME};
    	int[] to = new int[] {R.id.text1};
    	SimpleCursorAdapter users = new SimpleCursorAdapter(this, R.layout.users_row, mCursor, from, to);
        setListAdapter(users);
		
	}
	
	private void setListAdapter(SimpleCursorAdapter users) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
